package com.mao.douyin.demo.apis.controller;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.io.IOException;

/**
 * @author maodong
 * @Email 598129643@qq.com
 * @create 2021-03-23 9:40
 */
@RestController
public class QuShuiYinController {

    @PostMapping("/getQuShuiYinlink")
    @ResponseBody
    public ResponseEntity getQuShuiYinlink(@RequestBody String source){
        Dy dy=new Dy();
        ResponseEntity target=dealWithSource(dy,source);
        return target;
    }

    private ResponseEntity<String> dealWithSource(Dy dy,String source) {
        //获得tf文本框输入的需要解析的地址
        String text="";
        text=source;
        dy.str=text;
        if (text.length()==0){
            return ResponseEntity.badRequest().body("地址为空");
        }else {
            try {
                //对地址进行解析
                dy.getNum();
                dy.getWZ();
                dy.doGet();
                return ResponseEntity.ok(dy.strend) ;
            } catch (IOException ioException) {
                ioException.printStackTrace();
                return ResponseEntity.badRequest().body("地址错误");
            }catch (StringIndexOutOfBoundsException e1){
                e1.printStackTrace();
                return ResponseEntity.badRequest().body("地址错误");
            }
        }
    }

}
